package cn.tradewin.advisor.pages.security;

import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

import cn.tradewin.advisor.persist.model.Permissions;
import cn.tradewin.advisor.persist.services.AdvisorSecurityService;

public class AddPerm {

	@Property
	private Permissions perm;
	
	@Inject
	private Logger log;
	
	@Inject
	private AdvisorSecurityService securityService;
	
	@Log
	void onPrepare() throws Exception {
		if (perm == null) {
			perm = new Permissions();
			perm.setPermId(securityService.getMaxPermId());
		}
	}

	@Log
	Object onSubmit() {
		try {
			securityService.addPerm(perm);
		} catch (Exception e) {
			log.debug(e.getMessage());
		}
		return PermBoard.class;
	}
}
